package com.demomaster.quickcompat.widget.button;

import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.os.Build;
import android.util.AttributeSet;
import android.util.TypedValue;

import androidx.appcompat.widget.AppCompatButton;

import com.demomaster.quickcompat.R;
import com.demomaster.quickcompat.widget.base.QuickView;
import com.demomaster.quickcompat.widget.base.QuickViewImpl;
import com.demomaster.quickcompat.widget.base.QuickViewUtil;

/**
 * Created by Squirrel桓 on 2019/1/5.
 */
public class QuickButton extends AppCompatButton  implements QuickView {

    public QuickButton(Context context) {
        super(context);
        init(context, null, R.attr.QuickButton);
    }

    public QuickButton(Context context, AttributeSet attrs) {
        super(context, attrs, R.attr.QuickButton);
        init(context, attrs, R.attr.QuickButton);
    }

    public QuickButton(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context, attrs, defStyleAttr);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        if (quickViewImpl.attribute.isSquare) {
            super.onMeasure(widthMeasureSpec, widthMeasureSpec);
        } else {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        }
    }

    QuickViewImpl quickViewImpl;
    public void init(Context context, AttributeSet attrs, int defStyleAttr) {
        quickViewImpl = new QuickViewImpl(this, attrs, defStyleAttr);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        QuickViewUtil.draw(canvas,quickViewImpl);
        super.onDraw(canvas);
        QuickViewUtil.drawBadge(this,canvas,quickViewImpl);
    }

    @Override
    public void setClickable(boolean clickable) {
        super.setClickable(clickable);
        QuickViewUtil.setClickable(this);
    }
}
